﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Configuration;
using System.Collections.Specialized;

namespace KingSite.Library.Cache {
    public  class CacheHelper {
        static ICacheSetting cacheSetting = new CacheSetting();

        public static ICache GetInstance() {
            string[] type = cacheSetting.CacheType.Split(',');
            string a = type[1];
            string n = type[0];
            Assembly ass = Assembly.Load(a);
            Type[] t = ass.GetTypes();
            object o = ass.CreateInstance(n);
            return (ICache)o;
        }
    }

    public interface ICacheSetting {
        string CacheType { get; }
    }

    public class CacheSetting : ICacheSetting {

        public string CacheType {
            get {
                return ((NameValueCollection)ConfigurationManager.GetSection("KingSiteLibrary/Cache"))["CacheType"];
            }
        }

    }
}
